require '../lib/argser/parser.rb'

parser = Argser::Parser.new({
    options: {
        description: "This is a greeting application",
        usage:       "greeting [OPTIONS] NAME",
        details:     "Provided your age and your name, this application will greet you in a unique way.",
        info:        "For more information contact me at foo@/dev/null.com or try '--help'",
        unknown:     "What's '$p'?",
        fatal:       "There has been a weird error!!",
        help:        true
    },
    params: {
        age: {
            shortcut: :a,
            default:  18,
            type:     :integer,
            sanitize: lambda {|value, default| (value >= 18) ? value : :young},
            help:  "Specify your age",
            errors: {
                type:  "I can't believe you're '$v' years old",
                young: "You can't use this application unless you're older than 18!"
            }
        }
    },
    remaining: {
        type:    /[A-Z][A-Za-z]+\s[A-Z][A-Za-z]+/,
        minimum: 1,
        maximum: 1,
        callback: lambda {|values, default| puts "Alright, I got your name!"},
        help: "Specify your name and surname",
        errors: {
            type: "What!? Your name is '$v'!?"
        }
    }
})

parser.parse(ARGV)

comment = ''
if (parser.param? :age)
    comment = case parser.param(:age)
        when 18..20 then "you're a teenager!"
        when 21..30 then "you're a young man!"
        when 30..99 then "you're an adult!"
        when 100..1.0/0.0 then "you're awesome!"
    end
else
    comment = 'how old are you?'
end

puts "What's up #{parser.remaining[0]}? #{comment}"